<div class="been-send"><i class="icon icon-warning">$</i> 您需要在2个小时之内完成后续操作，否则您的本次操作将会失效！<br /><br />为保障您的账户安全，请先验证您的身份</div>
<form method="post">
    <ul>
        <li class="form-item">
            <label class="form-label">选择验证方式：</label><span class="form-act">
                <input type="hidden" id="key" name="key" value="{{secret}}" />
                <input type="hidden" id="account" name="account" value="{{account}}" />
                {{if  mobile }}
                <label class="form-sub-label">
                    <input type="radio" value="mobile" checked="" name="send_type" class="action-verify-method" />
                    <input type="hidden" value="{{mobile}}" name="mobile" />手机验证
                </label>
                {{/if}}
                {{if email}}
                <label class="form-sub-label">
                    <input type="radio" value="email" {{if !mobile}} checked="" {{/if}} name="send_type" class="action-verify-method" />
                    <input type="hidden" value="{{email}}" name="email" />邮箱验证
                </label>
                {{/if}}
            </span>
            {{if mobile}}
        <li class="form-item op-verify-mobile">
            <label class="form-label">手机号码：</label><span class="form-act">{{mobile}}  <a data="{{mobile}}" class="btn btn-caution action-get-verifycode"><span><span id="message">获取验证码</span></span></a></span>
        </li>
        <li class="form-item op-verify-mobile">
            <label class="form-label">填写验证码：</label><span class="form-act">
                <input type="text" name="vcode" id="mobilevcode" class="x-input" />
            </span><span class="caution-content"></span>
        </li>
        <li class="form-item-normal">
            <span class="form-act">
                <button type="submit" class="btn btn-caution btn-big"><span><span>下一步</span></span></button>
            </span>
        </li>
        {{/if}}
        {{if email}}
        <li class="form-item op-verify-email {{if mobile}}hide{{/if}}">
            <label class="form-label">邮箱地址：</label><span class="form-act">{{email}} <a data="{{email}}" class="btn btn-caution action-resend-email"><span><span>发送验证邮件</span></span></a></span>
        </li>
        <div class="been-send hide" id="emailmsg"><i class="icon icon-success">%</i> 邮件发送成功，请根据邮件中的连接地址进行后续修改操作!</div>
        {{/if}}
    </ul>
</form>
<script>
    jQuery("#forgot_content form").submit(function () {
        var key = jQuery("#key").val().trim();
        var account = jQuery("#account").val().trim()
        var vcode = jQuery("#mobilevcode").val().trim();
        if (!key || !account)
        {
            alert("缺少必要信息，请刷新重试");
            return false;
        }
        if (vcode === undefined || vcode.length < 1) {
            alert("验证码不能为空");
            return false;
        }
        jQuery.ajax({
            url: "/lostpwd/step3",
            type: "post",
            dataType:"json",
            data: { "key": key,"account":account,"vcode":vcode },
            success: function (data) {
                if (data.succ) {
                    jQuery(".step-2").removeClass("active");
                    jQuery(".step-3").addClass("active");
                    jQuery("#forgot_content").html(data.data);
                } else {
                    alert(data.msg); //错误
                }
            }
        });
      return false;
    });
    var timedCount = function (time, message) {
        var t = time, msg = message;
        if (!t) {
            var regx = new RegExp("(.*)\\((.*)\\)", "igm");
            var html = jQuery(".action-get-verifycode #message").html();
            var match = regx.exec(html)
            msg = match[1];
            t = match[2];
        }
        t--;
        if (t < 1) {
            jQuery(".action-get-verifycode").removeAttr("disabled");
            jQuery(".action-get-verifycode #message").html(msg);
            return;
        }
        jQuery(".action-get-verifycode #message").html(msg + "(" + t + ")");
        setTimeout(timedCount, 1000);
    };
    jQuery(".action-verify-method[name=send_type]").change(function () {
        if (jQuery(this).val() === "mobile") {
            jQuery(".op-verify-mobile").removeClass("hide");
            jQuery(".op-verify-email").addClass("hide");
        } else if (jQuery(this).val() === "email") {
            jQuery(".op-verify-mobile").addClass("hide");
            jQuery(".op-verify-email").removeClass("hide");
        }
    });
   //发送短信
    jQuery(".action-get-verifycode").click(function () {
        var mobile = jQuery(this).attr("data");
        jQuery.ajax({
            url: "/lostpwd/sendsms",
            dataType: "json",
            type: "POST",
            data: { "mobile": mobile },
            success: function (data) {
                if (data.succ) {
                    timedCount(120, jQuery(".action-get-verifycode #message").html());
                } else {
                    alert(data.msg);
                }
            }
        });
        return false;
    });
  //发送邮件
    jQuery(".action-resend-email").click(function () {
        var email = jQuery(this).attr("data");
        var key = jQuery("#key").val().trim();
        var account = jQuery("#account").val().trim();
        if (!key || !account) {
            alert("缺少必要信息，请刷新重试");
            return false;
        }
        jQuery.ajax({
            url: "/lostpwd/email",
            dataType: "json",
            type: "POST",
            data: { "email": email, "key": key, "account": account },
            success: function (data) {
                if (data.succ) {
                    jQuery("#emailmsg").removeClass("hide");
                } else {
                    alert(data.msg);
                }
            }
        })
        return false
    });
</script>